home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / cross / ava-0.2.5.lha / ava-0.2.5 / src / Reports.C < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-23  |  4.0 KB  |  145 lines

  1. /*
  2.   Reports.C
  3.   
  4.   Reports information on current file being compiled,
  5.   warnnings, errors, segmantation, symbols and complete listing.
  6.   
  7.   Uros Platise, dec 1998
  8. */
  9.  
  10. #include <string.h>
  11. #include <stdio.h>
  12. #include <time.h>
  13. #include "Global.h"
  14. #include "Reports.h"
  15.  
  16. TReports::~TReports(){
  17.   if (ErrorCnt>1){
  18.     fprintf(stderr,"Total %d error%c ...\n",ErrorCnt,(ErrorCnt==1)?0:'s');}
  19.   if (logfile!=NULL){delete logfile; logfile=NULL;}
  20. }
  21.  
  22. void TReports::Config(char* logFileName){
  23.   try{
  24.     if (logfile!=NULL){delete logfile; logfile=NULL;}
  25.     if (logfile==NULL){logfile = new TFile(logFileName,"a+");}
  26.   }catch(file_error& x){Error(x);}
  27. }
  28.  
  29. void TReports::FileStatus(int _verbose_level){
  30.   Info(_verbose_level, "%s:%ld: ", preproc.name(), preproc.line());
  31. }
  32.  
  33. void TReports::Info(int _verbose_level, const char* fmt, ...){
  34.   if (_verbose_level > verbose_level){return;}
  35.   va_list ap;
  36.   va_start(ap,fmt); 
  37.   if (logfile!=NULL){vfprintf(logfile->stream(),fmt,ap);}
  38.   else{vfprintf(stderr,fmt,ap);}
  39.   va_end(ap);  
  40. }
  41.  
  42. char* TReports::Today(){
  43.   gt=time(NULL); return asctime(localtime(>));
  44. }
  45.  
  46. void TReports::Warnning(const char* fmt, ...){
  47.   va_list ap;
  48.   va_start(ap,fmt);
  49.   fprintf(stderr,"Warning: ");
  50.   if (logfile!=NULL){
  51.     fprintf(logfile->stream(),"Warning: ");
  52.     vfprintf(logfile->stream(),fmt,ap); fprintf(logfile->stream(),"\n");}  
  53.   vfprintf(stderr,fmt,ap);
  54.   fprintf(stderr,"\n");
  55.   va_end(ap);    
  56. }
  57.  
  58. void TReports::Warnning(TGroup group, const char* fmt, ...){
  59.   va_list ap;
  60.   va_start(ap,fmt);  
  61.   if (logfile!=NULL){
  62.     fprintf(logfile->stream(),"Warning: ");
  63.     vfprintf(logfile->stream(),fmt,ap); fprintf(logfile->stream(),"\n");}  
  64.   if (group&GroupMask){
  65.     fprintf(stderr,"Warning: "); vfprintf(stderr,fmt,ap); fprintf(stderr,"\n");
  66.   }  
  67.   va_end(ap);      
  68. }
  69.  
  70. void TReports::Error(global_error& error){
  71.   error.print();
  72.   if (ErrorCnt++==MAX_ERRORS_BEFORE_HALT){
  73.     throw generic_error("Maximum numbers of errors reached - exiting.");}
  74. }
  75.  
  76. void TListing::Create(const char* asmFname){
  77.   if (!listingEnabled){return;}
  78.   /* close listings and prepeare listing file name */
  79.   Unroll();
  80.   char* fullstop = strrchr(asmFname,'.');
  81.   char listFileName [PPC_MAXFILELEN];
  82.   if (fullstop!=NULL){
  83.     strncpy(listFileName,asmFname,fullstop-asmFname);
  84.     strcpy(&listFileName[fullstop-asmFname],".lst");
  85.   }else{strcpy(listFileName,asmFname);strcat(listFileName,".lst");}
  86.  
  87.   srclP = new TFile(asmFname, "r");
  88.   dstlP = new TFile(listFileName, "w");    
  89. }
  90.  
  91. void TListing::GotoLine(long ln){
  92.   if (!listingEnabled){return;}
  93.   /* FLUSH buffer */
  94.   if (strlen(codeBuf)>0 && splitStr==true){
  95.     CopyNextLine(false); splitStr=false;}    
  96.   
  97.   /* copy all lines up to ln-1, and then wait at ln */  
  98.   while((clineNo+1)<ln){CopyNextLine();}
  99. }
  100.  
  101. void TListing::CopyNextLine(bool addAsmSource=true){
  102.   int codeBufLen=strlen(codeBuf);
  103.   if (codeBufLen>0){
  104.     if (codeBufLen<=codeWidth){
  105.       fprintf(dstlP->stream(), "%*.*lx: %*.*s ;\t",
  106.         addrWidth, addrWidth, addrBuf,  -codeWidth, codeWidth, codeBuf);      
  107.     }else{
  108.       fprintf(dstlP->stream(), "%*.*lx: %*.*s\n",
  109.         addrWidth, addrWidth, addrBuf,  -codeBufLen, codeBufLen, codeBuf);
  110.       codeBufLen=0;
  111.     }        
  112.   }
  113.   if (addAsmSource==true){
  114.     if (srclP()!=NULL){    
  115.       if (fgets(codeBuf, LX_LINEBUF, srclP->stream())!=NULL){
  116.         if (codeBufLen==0){
  117.           fprintf(dstlP->stream(), "%*.0s   ;\t", addrWidth+codeWidth, "");}
  118.         fputs(codeBuf, dstlP->stream());
  119.         if (feof(srclP->stream())){fputs("\n", dstlP->stream());}
  120.       }else{srclP=0;}    
  121.     }
  122.     clineNo++;
  123.   }
  124.   codeBuf[0]=0;
  125.   if (srclP()==NULL){fputs("\n", dstlP->stream());}  
  126. }
  127.  
  128. void TListing::Codecat(const char* code){
  129.   if (!listingEnabled){return;}
  130.   if (srclP()!=NULL){
  131.     if ((strlen(code)+strlen(codeBuf)) > MAX_CODEWIDTH){
  132.       CopyNextLine(false);splitStr=true;}
  133.     if (strlen(codeBuf)==0){addrBuf=addrCnt;}    
  134.     strcat(codeBuf,code);
  135.     addrCnt += strlen(code) >> 1;
  136.   }
  137. }
  138.  
  139. void TListing::Unroll(){
  140.   while(srclP()!=NULL){CopyNextLine();}
  141.   srclP=0; dstlP=0; clineNo=0; addrWidth=4; codeWidth=4; addrCnt=addrBuf=0; 
  142.   splitStr=false;
  143. }
  144.  
  145.